(function($) {
	$.fn.listScroll = function(options) {
		var options = $.extend({
			scrollList      : '.scroll-list',
			prevBtn         : '.prev',
			nextBtn         : '.next',
			direction       : 'horizonal',
			speed           : 300,
			autoPlay        : true,
			interval  		: 4000
		}, options);
		
		var $scrollList      = $(options.scrollList);
		var $prevBtn         = $(options.prevBtn);
		var $nextBtn         = $(options.nextBtn);
		var direction        = options.direction;
		var speed            = options.speed;
		var autoPlay         = options.autoPlay;
		var interval = options.interval;
		var itemWidth  = $scrollList.children('li').outerWidth(true);
		var itemHeight = $scrollList.children('li').outerHeight(true);

		$(this).css({position: 'relative'}); 
		$scrollList.css({position: 'absolute'});
		if(direction == 'vertical') {
			var showprevItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:last').clone().prependTo($scrollList);
					$scrollList.css({top: -itemHeight});
					$scrollList.animate({top: 0}, speed, function() {
						$scrollList.find('li:last').remove();
					});
				}
			};
			var showNextItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:first').clone().appendTo($scrollList);
					$scrollList.animate({top: -itemHeight}, speed, function() {
						$scrollList.css({top: 0});
						$scrollList.find('li:first').remove();
					});
				}
			};
		}else {
			// 根据列表中li的个数动态设置滚动列表的宽度
			$scrollList.css({width:($scrollList.children('li').length + 1) * itemWidth});
			var showprevItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:last').clone().prependTo($scrollList);
					$scrollList.css({left:-itemWidth});
					$scrollList.animate({left: 0},speed,function() {
						$scrollList.find('li:last').remove();
					});
				}
			};
			var showNextItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:first').clone().appendTo($scrollList);
					$scrollList.animate({left: -itemWidth}, speed, function() {
						$scrollList.css({left: 0});
						$scrollList.find('li:first').remove();
					});
				}
			};

			$prevBtn.click(function() {
				showprevItem();
			});

			$nextBtn.click(function() {
				showNextItem();
			});
		}

		if(autoPlay) {
			listScrollTimer = setInterval(function() {
				showNextItem();
			}, interval);
			$(this).hover(function() {
				clearInterval(listScrollTimer);
			},function() {
				listScrollTimer = setInterval(function() {
					showNextItem();
				}, interval);
			});
		}
	}
})(jQuery);(function($) {
	$.fn.listScroll = function(options) {
		var options = $.extend({
			scrollList      : '.scroll-list',
			prevBtn         : '.prev',
			nextBtn         : '.next',
			direction       : 'horizonal',
			speed           : 300,
			autoPlay        : true,
			interval  		: 4000
		}, options);
		
		var $scrollList      = $(options.scrollList);
		var $prevBtn         = $(options.prevBtn);
		var $nextBtn         = $(options.nextBtn);
		var direction        = options.direction;
		var speed            = options.speed;
		var autoPlay         = options.autoPlay;
		var interval = options.interval;
		var itemWidth  = $scrollList.children('li').outerWidth(true);
		var itemHeight = $scrollList.children('li').outerHeight(true);

		$(this).css({position: 'relative'}); 
		$scrollList.css({position: 'absolute'});
		if(direction == 'vertical') {
			var showprevItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:last').clone().prependTo($scrollList);
					$scrollList.css({top: -itemHeight});
					$scrollList.animate({top: 0}, speed, function() {
						$scrollList.find('li:last').remove();
					});
				}
			};
			var showNextItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:first').clone().appendTo($scrollList);
					$scrollList.animate({top: -itemHeight}, speed, function() {
						$scrollList.css({top: 0});
						$scrollList.find('li:first').remove();
					});
				}
			};
		}else {
			// 根据列表中li的个数动态设置滚动列表的宽度
			$scrollList.css({width:($scrollList.children('li').length + 1) * itemWidth});
			var showprevItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:last').clone().prependTo($scrollList);
					$scrollList.css({left:-itemWidth});
					$scrollList.animate({left: 0},speed,function() {
						$scrollList.find('li:last').remove();
					});
				}
			};
			var showNextItem = function() {
				if(!$scrollList.is(':animated')) {
					$scrollList.find('li:first').clone().appendTo($scrollList);
					$scrollList.animate({left: -itemWidth}, speed, function() {
						$scrollList.css({left: 0});
						$scrollList.find('li:first').remove();
					});
				}
			};

			$prevBtn.click(function() {
				showprevItem();
			});

			$nextBtn.click(function() {
				showNextItem();
			});
		}

		if(autoPlay) {
			listScrollTimer = setInterval(function() {
				showNextItem();
			}, interval);
			$(this).hover(function() {
				clearInterval(listScrollTimer);
			},function() {
				listScrollTimer = setInterval(function() {
					showNextItem();
				}, interval);
			});
		}
	}
})(jQuery);